//
//  CCActionIntervalEx.h
//  airfight
//
//  Created by USER on 12-9-19.
//  Copyright (c) 2012年 moonriver. All rights reserved.
//

#ifndef airfight_CCActionIntervalEx_h
#define airfight_CCActionIntervalEx_h

#include "CCActionInterval.h"
#include "cocos2d.h"

USING_NS_CC;

class CC_DLL CCFiniteTimeActionEx : public CCAction
{
public:
    CCFiniteTimeActionEx()
    : m_DurationFrames(0)
    {}
    virtual ~CCFiniteTimeActionEx(){}
    //! get duration in seconds of the action
    inline int getDuration(void) { return m_DurationFrames; }
    //! set duration in seconds of the action
    inline void setDuration(int durationFrames) { m_DurationFrames = durationFrames; }
    
protected:
    //! duration in seconds
    int m_DurationFrames;
};

class CC_DLL CCActionIntervalEx : public CCFiniteTimeActionEx
{
public:
    /** initializes the action */
    bool initWithDuration(int durationFrames);
    
    /** returns true if the action has finished */
    virtual bool isDone(void);
    
    virtual CCObject* copyWithZone(CCZone* pZone);
    virtual void step(float dt);
    virtual void startWithTarget(CCNode *pTarget);
    
public:
    /** creates the action 
     @deprecated: This interface will be deprecated sooner or later.
     */
    CC_DEPRECATED_ATTRIBUTE static CCActionIntervalEx* actionWithDuration(int durationFrames);
    
    /** creates the action */
    static CCActionIntervalEx* create(int durationFrames);
    
public:
    //extension in CCGridAction 
    void setAmplitudeRate(CCFloat amp);
    CCFloat getAmplitudeRate(void);
    
protected:
    int m_ElapsedFrames;
    bool m_bFirstTick;
};

class CC_DLL CCSequenceEx : public CCActionIntervalEx
{
public:
    ~CCSequenceEx(void);
    
    /** initializes the action */
    bool initOneTwo(CCFiniteTimeActionEx *pActionOne, CCFiniteTimeActionEx *pActionTwo);
    
    virtual CCObject* copyWithZone(CCZone* pZone);
    virtual void startWithTarget(CCNode *pTarget);
    virtual void stop(void);
    virtual void update(float t);
public:
    /** helper constructor to create an array of sequenceable actions 
     @deprecated: This interface will be deprecated sooner or later.
     */
    CC_DEPRECATED_ATTRIBUTE static CCFiniteTimeActionEx* actions(CCFiniteTimeActionEx *pAction1, ...);
    /** helper contructor to create an array of sequenceable actions given an array 
     @deprecated: This interface will be deprecated sooner or later.
     */
    CC_DEPRECATED_ATTRIBUTE static CCFiniteTimeActionEx* actionWithArray(CCArray *arrayOfActions);
    /** creates the action 
     @deprecated: This interface will be deprecated sooner or later.
     */
    CC_DEPRECATED_ATTRIBUTE static CCSequenceEx* actionOneTwo(CCFiniteTimeActionEx *pActionOne, CCFiniteTimeActionEx *pActionTwo);
    
    /** helper constructor to create an array of sequenceable actions */
    static CCFiniteTimeActionEx* create(CCFiniteTimeActionEx *pAction1, ...);
    /** helper contructor to create an array of sequenceable actions given an array */
    static CCFiniteTimeActionEx* create(CCArray *arrayOfActions);
    /** creates the action */
    static CCSequenceEx* create(CCFiniteTimeActionEx *pActionOne, CCFiniteTimeActionEx *pActionTwo);
    
protected:
    CCFiniteTimeActionEx *m_pActionsEx[2];
    float m_split;
    int m_last;
};

class CC_DLL CCMoveToEx : public CCActionIntervalEx
{
public:
    /** initializes the action */
    bool initWithDuration(int durationframes, const CCPoint& position);
    
    virtual CCObject* copyWithZone(CCZone* pZone);
    virtual void startWithTarget(CCNode *pTarget);
    virtual void update(float ratio);
    
public:
    /** creates the action 
     @deprecated: This interface will be deprecated sooner or later.
     */
    CC_DEPRECATED_ATTRIBUTE static CCMoveToEx* actionWithDuration(int durationframes, const CCPoint& position);
    /** creates the action */
    static CCMoveToEx* create(int durationframes, const CCPoint& position);
protected:
    CCPoint m_endPosition;
    CCPoint m_startPosition;
    CCPoint m_delta;
};

class CC_DLL CCMoveByEx : public CCMoveToEx
{
public:
    /** initializes the action */
    bool initWithDuration(int durationframes, const CCPoint& position);
    
    virtual CCObject* copyWithZone(CCZone* pZone);
    virtual void startWithTarget(CCNode *pTarget);
    
public:
    /** creates the action 
     @deprecated: This interface will be deprecated sooner or later.
     */
    CC_DEPRECATED_ATTRIBUTE static CCMoveByEx* actionWithDuration(int durationframes, const CCPoint& position);
    /** creates the action */
    static CCMoveByEx* create(int durationframes, const CCPoint& position);
};

class CC_DLL CCBezierToEx : public CCActionIntervalEx
{
public:
    /** initializes the action with a duration and a bezier configuration */
    bool initWithDuration(int durationfrmes, CCArray* array);
    
    virtual CCObject* copyWithZone(CCZone* pZone);
    virtual void startWithTarget(CCNode *pTarget);
    virtual void update(float ratio);
    
public:
    /** creates the action with a duration and a bezier configuration 
     @deprecated: This interface will be deprecated sooner or later.
     */
    CC_DEPRECATED_ATTRIBUTE static CCBezierToEx* actionWithDuration(int durationfrmes, CCArray* array);
    /** creates the action with a duration and a bezier configuration */
    static CCBezierToEx* create(int durationfrmes, CCArray* array);
protected:
    CCArray *m_Array;
    CCPoint m_startPosition;
    float m_arrayX[10];
    float m_arrayY[10];
};

#endif
